import request from '@/config/axios'

// 发票记录 VO
export interface InvoiceRecordVO {
  id: number // 主键ID
  merchantId: number // 商家ID
  merchantName?: string // 商家名称
  rechargeIds: string // 充值记录ID
  invoiceTitle: string // 发票抬头
  taxNumber: string // 税号
  invoiceType: number // 发票类型
  amount: number // 开票金额
  status: number // 状态
  contactName: string // 联系人
  contactPhone: string // 联系电话
  contactEmail: string // 联系邮箱
  bankName: string // 开户银行
  bankAccount: string // 银行账号
  companyAddress: string // 公司地址
  companyPhone: string // 公司电话
  invoiceCode: string // 发票代码
  invoiceNumber: string // 发票号码
  pdfUrl: string // 电子发票
  rejectReason: string // 驳回原因
  operatorId: number // 操作人ID
  operatorName: string // 操作人姓名
  remark: string // 备注
}

// 开票请求参数
export interface OpenInvoiceReqVO {
  id: number
  status: number
  pdfUrl: string
  remark?: string
  invoiceTitle: string // 发票抬头
  taxNumber: string // 税号
  invoiceType: number // 发票类型
  amount: number // 开票金额
}

// 请求参数
export interface InvoiceRecordPageReqVO {
  pageNo: number
  pageSize: number
  merchantId?: number
  invoiceTitle?: string
  taxNumber?: string
  invoiceType?: number
  amount?: number
  status?: number
  contactName?: string
  contactPhone?: string
  contactEmail?: string
  bankName?: string
  bankAccount?: string
  companyAddress?: string
  companyPhone?: string
  invoiceCode?: string
  invoiceNumber?: string
  pdfUrl?: string
  rejectReason?: string
  createTime?: string[]
  operatorId?: number
  operatorName?: string
  remark?: string
}

// 发票记录 API
export const InvoiceRecordApi = {
  // 查询发票记录分页
  getInvoiceRecordPage: async (params: InvoiceRecordPageReqVO) => {
    return await request.get({ url: `/juliang/invoice-record/page`, params })
  },

  // 查询发票记录详情
  getInvoiceRecordById: async (id: number) => {
    return await request.get({ url: `/juliang/invoice-record/getById?id=` + id })
  },

  // 新增发票记录
  createInvoiceRecord: async (data: InvoiceRecordVO) => {
    return await request.post({ url: `/juliang/invoice-record/create`, data })
  },

  // 修改发票记录
  updateInvoiceRecord: async (data: InvoiceRecordVO) => {
    return await request.post({ url: `/juliang/invoice-record/update`, data })
  },

  // 修改发票记录状态
  updateInvoiceRecordStatus: async (id: number, status: number) => {
    const data = {
      id,
      status
    }
    return await request.post({ url: `/juliang/invoice-record/updateStatus`, data: data })
  },

  // 删除发票记录
  deleteInvoiceRecordById: async (id: number) => {
    return await request.get({ url: `/juliang/invoice-record/delete?id=` + id })
  },

  // 导出发票记录 Excel
  exportInvoiceRecord: async (params: InvoiceRecordPageReqVO) => {
    return await request.download({ url: `/juliang/invoice-record/export-excel`, params })
  },

  // 开具发票
  openInvoice: async (data: OpenInvoiceReqVO) => {
    return await request.post({ url: `/juliang/invoice-record/openInvoice`, data })
  },
}
